RedemptionRequest = new Object();

RedemptionRequest.requestType = 'U';
var disableDates = [];
var redemption_id = null;

var red_customer_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'code', 'title', 'initials', 'surname', 'denotedByInitials', 'nicPassport', 'customerType', 'accountType', 'residential', 'fmId', 'correspondingAddress',
			'generalAddress', 'phone', 'fax', 'corresEmail', 'corresFax', 'corresPost', 'corresInst', 'bankInstrution', 'organizationName', 'businessRegNo', 'businessAddress' ]
});

var store = Ext.create('Ext.data.Store', {
	fields : [ 'redemptionTypeId', 'redemptionType' ],
	data : [ {
		"redemptionTypeId" : "U",
		"redemptionType" : "Unit Wise"
	}, {
		"redemptionTypeId" : "V",
		"redemptionType" : "Value Wise"
	} ]
});

var red_fund_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'name', 'code', 'unitValue' ]
});

var red_redemption = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'redemptionCode', 'redemptionType', 'confirmDate', 'expectedDate', 'requestDate', 'status', 'totAmount', 'totUnit', 'customer', 'fund_id',
			'redemptionReqToRedemtions', 'invenstmentCode', 'recordUser', 'recordType', 'unitprice', 'customer_name' ]
});

var summary_store = Ext.create('Ext.data.Store', {
	fields : [ 'id', 'invenstmentCode', 'date', 'amount', 'noOfUnits', 'summaryType', 'status' ]
});

var red_customer_investment_store = Ext.create('Ext.data.Store', {
	fields : [ 'confirmDate', 'fund_id', 'amount', 'unitPrice', 'noOfUnits', 'customer', 'invenstmentCode', 'investmentId', 'releaseAmount', 'releaseUnits', 'success',
			'resulteMsg', 'remainingUnits' ]
});

RedemptionRequest.getInvestmentGrid = function() {
	var grid = null;
	var totalval = null;
	var totalUnit = null;
	RedemptionRequest.requestType = 'U';

	var rowEditing = Ext.create('Ext.grid.plugin.CellEditing', {
		clicksToEdit : 1
	});
	grid = Ext.create('Ext.grid.Panel', {
		id : 'gridpanel',
		store : red_customer_investment_store,
		features : [ {
			ftype : 'summary'
		} ],
		columns : [ {
			dataIndex : 'invenstmentCode',
			header : 'Invesment Code',
		}, {
			header : 'Investment Date',
			dataIndex : 'confirmDate',
			xtype : 'datecolumn',
			format : 'd/m/Y'
		}, {
			header : 'Amount',
			dataIndex : 'amount',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1
		}, {
			header : 'Issued Units',
			dataIndex : 'noOfUnits',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1
		}, {
			header : 'Remaining Units',
			dataIndex : 'remainingUnits',
			id : 'remainingUnits',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1
		}, {
			header : 'Release Amount',
			dataIndex : 'releaseAmount',
			id : 'releaseAmount',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			summaryType : 'sum',
			flex : 1,
			summaryRenderer : function(value, summaryData, dataIndex) {
				if (value != '')
					totalval = Ext.util.Format.number(value, '0,000.0000');
				else
					totalval = Ext.util.Format.number(0, '0,000.0000');
				return totalval;
			},
			getEditor : function(record) {
				if (RedemptionRequest.requestType == 'V') {
					var max = grid.getView().getSelectionModel().getSelection()[0].get('remainingUnits') * grid.getView().getSelectionModel().getSelection()[0].get('unitPrice');
					return Ext.create('Ext.grid.CellEditor', {
						field : {
							xtype : 'numberfield',
							hideTrigger : true,
							keyNavEnabled : false,
							msgTarget : 'side',
							mouseWheelEnabled : false,
							decimalPrecision : 4,
							maxValue : max
						}
					});
				} else
					return false;
			}
		}, {
			header : 'Release Units',
			dataIndex : 'releaseUnits',
			id : 'releaseUnits',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1,
			summaryType : 'sum',
			summaryRenderer : function(value, summaryData, dataIndex) {
				if (value != '')
					totalUnit = Ext.util.Format.number(value, '0,000.0000');
				else
					totalUnit = Ext.util.Format.number(0, '0,000.0000');
				return totalUnit;
			},
			getEditor : function(record) {
				if (RedemptionRequest.requestType == 'U') {
					return Ext.create('Ext.grid.CellEditor', {
						field : {
							xtype : 'numberfield',
							hideTrigger : true,
							keyNavEnabled : false,
							mouseWheelEnabled : false,
							msgTarget : 'side',
							decimalPrecision : 4,
							maxValue : grid.getView().getSelectionModel().getSelection()[0].get('remainingUnits')
						}
					});
				} else
					return false;
			}
		} ],
		height : 175,
		width : 400,
		plugins : [ rowEditing ]
	});

	grid.on('edit', function(editor, e) {

		var amonutField = Ext.getCmp('total_amount');
		var totalUnitField = Ext.getCmp('total_unit');
		var unitPrice = parseFloat(Ext.getCmp('unitprice').getValue().replace(/,/g, ''));

		if (unitPrice != null || unitPrice != "") {
			if (e.field == 'releaseAmount') {
				var enterdValue = e.record.data.releaseAmount;
				e.record.data.releaseUnits = enterdValue / unitPrice;
				e.record.commit();
			}

			if (e.field == 'releaseUnits') {
				var enterdValue = e.record.data.releaseUnits;
				e.record.data.releaseAmount = enterdValue * unitPrice;
				e.record.commit();
			}
			totalUnitField.setRawValue(totalUnit);
			amonutField.setRawValue(totalval);
		}

	});

	grid.store.on('load', function(store, records, options) {
		var amonutField = Ext.getCmp('total_amount');
		var totalUnitField = Ext.getCmp('total_unit');
		var redeType = Ext.getCmp('RedemptionType');
		Ext.each(records, function(record, index) {
			var unitPrice = record.get('unitPrice');
			if (redeType.getValue() == "V") {
				var enterdValue = record.get('releaseAmount');
				record.set('releaseUnits', enterdValue / unitPrice);
			}
			if (redeType.getValue() == "U") {
				var enterdValue = record.get('releaseUnits');
				record.set('releaseAmount', enterdValue * unitPrice);
			}
		}, this);
		totalUnitField.setRawValue(totalUnit);
		amonutField.setRawValue(totalval);
	}, grid);

	return Ext.create('Ext.form.FieldSet', {
		title : 'Investment Details',
		defaults : {
			anchor : '100%'
		},
		items : [ grid ]
	});
};

RedemptionRequest.getPlageRedemption = function() {
	var summarygrid = null;
	summarygrid = Ext.create('Ext.grid.Panel', {
		store : summary_store,
		columns : [ {
			dataIndex : 'invenstmentCode',
			header : 'Invesment Code',
		}, {
			header : 'Date',
			dataIndex : 'date',
			xtype : 'datecolumn',
			format : 'd/m/Y'
		}, {
			header : 'Amount',
			dataIndex : 'amount',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1
		}, {
			header : 'No Of Units',
			dataIndex : 'noOfUnits',
			xtype : 'numbercolumn',
			format : '0,000.0000',
			align : 'right',
			flex : 1
		}, {
			header : 'Pledge / Redemption',
			dataIndex : 'summaryType',
			flex : 1
		}, {
			header : 'Status',
			dataIndex : 'status',
			flex : 1,
		} ],
		height : 100,
		width : 400
	});

	return Ext.create('Ext.form.FieldSet', {
		title : 'Pledge / Unconfirm Redemption Details',
		defaults : {
			anchor : '100%'
		},
		items : [ summarygrid ]
	});
};

RedemptionRequest.getBasicDetails = function() {

	return Ext.create('Ext.form.FieldSet', {

		defaults : {
			anchor : '100%'
		},
		items : [ {
			xtype : 'fieldcontainer',
			layout : 'hbox',
			items : [ {
				xtype : 'displayfield',
				fieldLabel : 'Request Date',
				name : 'requestDate',
				labelWidth : 110,
				submitValue : true,
				padding : '0 15 0 0',
				value : Ext.Date.format(new Date(), "d/m/Y"),
				flex : 1
			}, {
				xtype : 'displayfield',
				fieldLabel : 'Status',
				flex : 1,
				labelWidth : 80,
				submitValue : true,
				name : 'status',
				value : 'INITIAL'
			} ]
		}, {
			xtype : 'combo',
			flex : 1,
			labelWidth : 110,
			anchor : '40%',
			fieldLabel : 'Redemption Type',
			store : store,
			value : 'U',
			name : 'redemptionType',
			id : 'RedemptionType',
			valueField : 'redemptionTypeId',
			displayField : 'redemptionType',
			listeners : {
				change : function(cmp) {
					RedemptionRequest.requestType = cmp.getValue();
					Ext.getCmp('gridpanel').getStore().load();
					Ext.getCmp('fund').clearValue();
				}
			}
		}, {
			xtype : 'combo',
			labelWidth : 110,
			store : red_customer_store,
			valueField : 'id',
			displayField : 'code',
			fieldLabel : 'Customer <span style="color:red">*</span>',
			anchor : '70%',
			allowBlank : false,
			id : 'customer',
			msgTarget : 'under',
			name : 'customer',
			queryMode : 'local',
			isLoaded : false,
			tpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '<div class="x-boundlist-item">{code} - {surname}</div>', '</tpl>'),
			displayTpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '{code} - {surname}', '</tpl>'),
			listeners : {
				expand : function(combo, opt) {
					if (!combo.isLoaded) {
						Ext.Ajax.request({
							url : 'getCustomer.action',
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								combo.getStore().loadRawData(obj.customerBeans);
								combo.isLoaded = true;
							}
						});
					}
				},
				change : function(list, record) {
					if (redemption_id == null) {
						Ext.Ajax.request({
							url : 'getInvestmentByCustomer.action',
							params : {
								"customer_id" : list.getValue()
							},
							success : function(response) {
								var obj = Ext.decode(response.responseText);
								red_customer_investment_store.loadRawData(obj.redemptionInvestmentDtos);
							}
						});
					}
				}
			},
			listConfig : {
				listeners : {
					itemclick : function(list, record) {
						if (redemption_id == null) {
							var fundid = Ext.getCmp('fund').getValue();
							if (fundid != null) {
								if (record.get('code') != null) {
									Ext.Ajax.request({
										url : 'getInvestmentByCustomer.action',
										params : {
											"customer_id" : record.get('id'),
											"invest_fund_id" : fundid
										},
										success : function(response) {
											var obj = Ext.decode(response.responseText);
											red_customer_investment_store.removeAll();
											red_customer_investment_store.loadRawData(obj.redemptionInvestmentDtos);
										}
									});

									Ext.Ajax.request({
										url : 'getSummaryDetails.action',
										params : {
											"customer_id" : record.get('id'),
											"invest_fund_id" : fundid
										},
										success : function(response) {
											var obj = Ext.decode(response.responseText);
											summary_store.removeAll();
											summary_store.loadRawData(obj.detailDtos);
										}
									});
								}
							}
						}
					}
				}
			}
		}, {
			xtype : 'fieldcontainer',
			layout : 'hbox',
			items : [ {
				xtype : 'combo',
				fieldLabel : 'Fund<span style="color:red">*</span>',
				flex : 1,
				labelWidth : 110,
				anchor : '70%',
				id : 'fund',
				padding : '0 10 0 0',
				store : red_fund_store,
				valueField : 'id',
				displayField : 'code',
				emptyText : 'Select a Fund...',
				isLoaded : false,
				allowBlank : false,
				msgTarget : 'under',
				name : 'fund_id',
				queryMode : 'local',
				tpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '<div class="x-boundlist-item">{code} - {name}</div>', '</tpl>'),
				displayTpl : Ext.create('Ext.XTemplate', '<tpl for=".">', '{code} - {name}', '</tpl>'),
				listeners : {
					expand : function(combo, opt) {
						if (!combo.isLoaded) {
							Ext.Ajax.request({
								url : 'getFundVsUnitValue.action',
								success : function(response) {
									var obj = Ext.decode(response.responseText);
									combo.getStore().loadRawData(obj.fundDtos);
									combo.isLoaded = true;
								}
							});
						}
					}
				},
				listConfig : {
					listeners : {
						itemclick : function(list, record) {
							Ext.getCmp('unitprice').setValue(Ext.util.Format.number(record.get('unitValue'), '0,000.0000'));
							if (redemption_id == null) {
								var customerid = Ext.getCmp('customer').getValue();
								if (customerid != null) {
									if (record.get('code') != null) {
										Ext.Ajax.request({
											url : 'getInvestmentByCustomer.action',
											params : {
												"invest_fund_id" : record.get('id'),
												"customer_id" : customerid
											},
											success : function(response) {
												var obj = Ext.decode(response.responseText);
												red_customer_investment_store.removeAll();
												red_customer_investment_store.loadRawData(obj.redemptionInvestmentDtos);
											}
										});
										Ext.Ajax.request({
											url : 'getSummaryDetails.action',
											params : {
												"customer_id" : customerid,
												"invest_fund_id" : record.get('id')
											},
											success : function(response) {
												var obj = Ext.decode(response.responseText);
												summary_store.removeAll();
												summary_store.loadRawData(obj.detailDtos);
											}
										});
									}
								}
							}
						}
					}
				}
			}, {
				xtype : 'textfield',
				fieldLabel : 'Unit Price',
				labelWidth : 90,
				readOnly : true,
				allowBlank : false,
				id : 'unitprice',
				name : 'unitprice',
				fieldStyle : "text-align:right;",
				maskRe : /[\d\,.]/,
				listeners : {
					blur : function() {
						var up = this.value.replace(/,/g, '');
						this.setRawValue(Ext.util.Format.number(up, '0,000.0000'));
					},
					render : function() {
						this.setRawValue(Ext.util.Format.number(this.value, '0,000.0000'));
					}
				}
			} ]
		}, {
			xtype : 'fieldcontainer',
			layout : 'hbox',
			items : [ {
				xtype : 'textfield',
				fieldLabel : 'Total Amount',
				labelWidth : 110,
				flex : 1,
				readOnly : true,
				name : 'totAmount',
				padding : '0 15 0 0',
				id : 'total_amount',
				fieldStyle : "text-align:right;",
				maskRe : /[\d\,.]/,
				listeners : {
					blur : function() {
						var totaluni = this.value.replace(/,/g, '');
						this.setRawValue(Ext.util.Format.number(totaluni, '0,000.0000'));
					},
					render : function() {
						this.setRawValue(Ext.util.Format.number(this.value, '0,000.0000'));
					}
				}
			}, {
				xtype : 'textfield',
				fieldLabel : 'Total Unit',
				labelWidth : 140,
				flex : 1,
				readOnly : true,
				name : 'totUnit',
				id : 'total_unit',
				fieldStyle : "text-align:right;",
				maskRe : /[\d\,.]/,
				listeners : {
					blur : function() {
						var totval = this.value.replace(/,/g, '');
						this.setRawValue(Ext.util.Format.number(totval, '0,000.0000'));
					},
					render : function() {
						this.setRawValue(Ext.util.Format.number(this.value, '0,000.0000'));
					}
				}
			} ]
		}, {
			xtype : 'fieldcontainer',
			layout : 'hbox',
			items : [ {
				xtype : 'datefield',
				labelWidth : 110,
				fieldLabel : 'Expected Date<span style="color:red">*</span>',
				format : 'd/m/Y',
				msgTarget : 'under',
				allowBlank : false,
				minValue : new Date(),
				flex : 1,
				disabledDays : [ 0, 6 ],
				id : 'expectedDate',
				name : 'expectedDate',
				padding : '0 15 0 0'
			}, {
				xtype : 'datefield',
				format : 'd/m/Y',
				labelWidth : 140,
				name : 'confirmDate',
				id : 'confirmDate',
				disabledDays : [ 0, 6 ],
				fieldLabel : 'Confirm Date',
				minValue : new Date(),
				flex : 1
			} ]

		} ]
	});
};

RedemptionRequest.getCeneterPanel = function() {

	var basics = RedemptionRequest.getBasicDetails();

	var invetsmentGrid = RedemptionRequest.getInvestmentGrid();
	var summarygrid = RedemptionRequest.getPlageRedemption();

	red_customer_investment_store.removeAll();
	summary_store.removeAll();

	return Ext.create('Ext.form.FormPanel', {
		title : 'Redemption Request',
		bodyPadding : 20,
		id : 'redemption_form',
		autoScroll : true,
		frame : true,
		defaults : {
			labelWidth : 120,
			anchor : '70%',
		},
		fieldDefaults : {
			labelAlign : 'left'
		},
		items : [ {
			xtype : 'fieldcontainer',
			items : [ {
				xtype : 'triggerfield',
				emptyText : 'Search Redemption',
				triggerCls : 'x-form-search-trigger',
				width : 300,
				name : 'redemptionCode',
				style : 'float:right;',
				listeners : {
					specialkey : function(field, e) {
						if (e.getKey() == e.ENTER) {

						}
					}
				},
				onTriggerClick : function() {
					var window = null;
					Ext.Ajax.request({
						url : 'getRedemption.action',
						success : function(response) {
							var obj = Ext.decode(response.responseText);
							red_redemption.removeAll();
							red_redemption.loadRawData(obj.redemptionDtos);
						}
					});
					if (!window) {
						window = Ext.create('Ext.window.Window', {
							title : 'Redemption',
							height : 330,
							frame : true,
							width : 500,
							constrain : true,
							resizable : false,
							modal : true,
							layout : {
								type : 'fit'
							},
							items : [ {
								xtype : 'gridpanel',
								defaults : {
									anchor : '100%'
								},
								store : red_redemption,
								columns : [ {
									text : 'Redemption Code',
									dataIndex : 'redemptionCode',
									flex : 1
								}, {
									text : 'Name',
									dataIndex : 'customer_name',
									flex : 1
								} ],
								listeners : {
									itemdblclick : function(dv, record, item, index, e) {
										var data = record.data;
										RedemptionRequest.setFormFields(data, record);
										window.hide();
									}
								}
							} ]
						});
					}
					;
					if (window.isVisible()) {
						window.hide();
					} else {
						window.show();
					}

				}
			} ]
		}, basics, summarygrid, invetsmentGrid ],
		buttonAlign : 'center',
		buttons : [ {
			text : 'Cancel',
			handler : function() {
				App.Core.removeScreen();
			}
		}, {
			text : 'Reset',
			handler : function() {
				this.up('form').getForm().reset();
				redemption_id = null;
				if (App.screenPermiton.getAt(0).data.create == 0)
					Ext.getCmp('save').disable();
				else
					Ext.getCmp('save').enable();
				Ext.getCmp('save').setText('Save');
				Ext.getCmp('confirm').disable();
				Ext.getCmp('reject').disable();
				Ext.getCmp('gridpanel').getStore().removeAll();
			}
		}, {
			text : 'Save',
			id : 'save',
			handler : function() {
				var form = this.up('form').getForm();
				var grids = Ext.getCmp('gridpanel');
				if (form.isValid()) {
					var redemDetails = [];
					grids.getStore().each(function(record) {
						if (record.get('releaseUnits') > 0) {
							var obj = {
								"investmentId" : record.get("investmentId"),
								"confirmDate" : record.get("confirmDate"),
								"amount" : record.get("amount"),
								"noOfUnits" : record.get("noOfUnits"),
								"releaseAmount" : record.get("releaseAmount"),
								"releaseUnits" : record.get("releaseUnits"),
								"unitPrice" : record.get("unitPrice"),
								"remainingUnits" : record.get("remainingUnits")
							};
							console.log(record.get("investmentId"));
							redemDetails.push(obj);
						}
					});
					if (redemption_id == null) {
						form.url = 'addRedemption.action';
						form.submit({
							params : {
								"redemDetails" : Ext.encode(redemDetails),
							},
							success : function(form, action) {
								form.reset();
								redemption_id = null;
								Ext.getCmp('save').setText('Save');
								Ext.Msg.alert('Success', 'Saved Successfully');
								Ext.getCmp('gridpanel').getStore().removeAll();
							},
							failure : function(form, action) {
								Ext.Msg.alert('Failed', action.result.resulteMsg);
							}
						});
					} else {
						form.url = 'updateRedemption.action';
						form.submit({
							params : {
								"redemDetails" : Ext.encode(redemDetails),
								"redemption_id" : redemption_id
							},
							success : function(form, action) {
								form.reset();
								redemption_id = null;
								Ext.getCmp('save').setText('Save');
								Ext.Msg.alert('Success', 'Saved Successfully');
								Ext.getCmp('gridpanel').getStore().removeAll();
							},
							failure : function(form, action) {
								Ext.Msg.alert('Failed', action.result.resulteMsg);
							}
						});
					}
				}
			}
		}, {
			text : 'Confirm',
			id : 'confirm',
			disabled : true,
			handler : function() {
				var form = this.up('form').getForm();
				var confirmDate = Ext.getCmp('confirmDate');
				if (redemption_id != null) {
					if (form.isValid()) {
						if (confirmDate.getValue() != null) {
							form.url = 'redemptionconfirm.action';
							form.submit({
								params : {
									"redemption_id" : redemption_id
								},
								success : function(form, action) {
									form.reset();
									investmentId = null;
									Ext.getCmp('save').setText('Save');
									Ext.Msg.alert('Success', 'Redemption Confirmed');
									Ext.getCmp('gridpanel').getStore().removeAll();
								},
								failure : function(form, action) {
									Ext.MessageBox.show({
										title : 'Failed',
										msg : action.result.resulteMsg,
										buttons : Ext.MessageBox.OK,
										icon : 'icon_warning'
									});
								}
							});
						} else {
							Ext.Msg.alert('Error', 'Enter the confirmation Details');
						}
					}
				} else {
					Ext.Msg.alert('Info', 'Select the Redemtion');
				}
			}
		}, {
			text : 'Reject',
			id : 'reject',
			disabled : true,
			handler : function() {
			}
		} ],
		listeners : {
			render : function(p) {
				Ext.Ajax.request({
					url : 'getBankHoliday.action',
					success : function(response) {
						var obj = Ext.decode(response.responseText);
						HolidayCalendar.holiday_store.removeAll();
						HolidayCalendar.holiday_store.loadRawData(obj.calendarDtos);
						HolidayCalendar.holiday_store.each(function(record) {
							disableDates.push(record.get('date'));
						});
						Ext.getCmp('expectedDate').setDisabledDates(disableDates);
						Ext.getCmp('confirmDate').setDisabledDates(disableDates);
					}
				});

				if (App.screenPermiton.getAt(0).data.create == 0)
					Ext.getCmp('save').disable();
				else
					Ext.getCmp('save').enable();
			}
		}
	});
};

RedemptionRequest.setFormFields = function(data, record) {
	var formPanl = Ext.getCmp('redemption_form');
	redemption_id = data.id;

	Ext.Ajax.request({
		url : 'getCustomer.action',
		success : function(response) {
			var obj = Ext.decode(response.responseText);
			red_customer_store.loadRawData(obj.customerBeans);
			Ext.getCmp('customer').isLoaded = true;
		}
	});

	Ext.Ajax.request({
		params : {
			"redemtion_id" : redemption_id
		},
		url : 'getRedemtionsDetails.action',
		success : function(response) {
			var obj = Ext.decode(response.responseText);
			red_customer_investment_store.loadRawData(obj.redemptionInvestmentDtos);
		}
	});

	Ext.Ajax.request({
		url : 'getSummaryDetails.action',
		params : {
			"customer_id" : data.customer,
			"invest_fund_id" : data.fund_id
		},
		success : function(response) {
			var obj = Ext.decode(response.responseText);
			summary_store.removeAll();
			summary_store.loadRawData(obj.detailDtos);
		}
	});

	if (data.status == "CONFIRM") {
		Ext.getCmp('save').disable();
		Ext.getCmp('reject').disable();
		Ext.getCmp('confirm').disable();
		Ext.Ajax.request({
			url : 'getFundVsUnitValue.action',
			success : function(response) {
				var obj = Ext.decode(response.responseText);
				red_fund_store.loadRawData(obj.fundDtos);
				Ext.getCmp('fund').isLoaded = true;
			}
		});
	} else if (data.status == "INITIAL") {
		Ext.Ajax.request({
			url : 'getFundVsUnitValue.action',
			success : function(response) {
				var obj = Ext.decode(response.responseText);
				red_fund_store.loadRawData(obj.fundDtos);
				Ext.getCmp('fund').isLoaded = true;
				unitvalue = red_fund_store.findBy(function(record, id) {
					if (record.get('id') === data.fund_id) {
						Ext.getCmp('unitprice').setValue(Ext.util.Format.number(record.get('unitValue'), '0,000.0000'));
						return record.get('unitValue');
					}
					return null;
				});
			}
		});
		if (App.screenPermiton.getAt(0).data.create == 0)
			Ext.getCmp('save').disable();
		else
			Ext.getCmp('save').enable();

		if (App.screenPermiton.getAt(0).data.confirm == 0)
			Ext.getCmp('confirm').disable();
		else
			Ext.getCmp('confirm').enable();

		if (App.screenPermiton.getAt(0).data.reject == 0)
			Ext.getCmp('reject').disable();
		else
			Ext.getCmp('reject').enable();
		Ext.getCmp('save').setText('Update');

	}

	formPanl.getForm().loadRecord(record);

};
